<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .tab {
            margin: 100px auto; 
            width: 1000px;
        }
        .tab_list {
            background-color: #ccc;
            border: 1px solid #ccc;
            margin: 0 auto;
            height: 30px;
            width: 1000px;
            cursor: pointer;
        }
        .tab_list ul li {
            height: 30px;
            line-height: 30px;
            float: left;
            padding: 0 20px;
            text-align: center;
            /* margin-left: 30px; */
            /* padding-left:30px ; */
            list-style: none;
        }
        .current {
            background-color: red;
            
        }
        .item {
            display: none;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价(50000)</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display:block;">商品介绍模块</div>
            <div class="item">规格与包装模块</div>
            <div class="item">售后保障模块</div>
            <div class="item">商品评价模块</div>
            <div class="item">手机社区模块</div>
        </div>
    </div>
    <script>
        var tab_list = document.querySelector('.tab_list');
        var  lis = tab_list.querySelectorAll ('li');
        var item = document.querySelectorAll('.item')
        for ( var i = 0; i <lis.length; i++) {
            lis[i].setAttribute('index',i)
            lis[i].onclick = function () {
                for (i = 0; i<lis.length; i++) {
                    lis[i].className = '';
                }
                this.className = 'current';
                var index = this.getAttribute('index');
                console.log(index);
                for ( var i = 0; i <item.length;i++) {
                    item[i].style.display = '';
                }
                item[index].style.display = 'block';
            }
        }
        
    </script>
</body>
</html>